home *** CD-ROM | disk | FTP | other *** search
/ Fritz: All Fritz / All Fritz.zip / All Fritz / FILES / PROGNG_C / TURBOCU1.LZH / QMEM.C < prev    next >
Text File  |  1987-09-05  |  22KB  |  340 lines

  1. /*
  2.  
  3. THE APPLICATION OF QLIB FUNCTIONS IN A MEMORY EXPLORATION TOOL
  4.                GARRY J. VASS  [72307,3311]
  5.  
  6. Copyright (c), 1987, Telemacus Software Associates
  7.  
  8. This program provides enough to get QLIB registrants
  9. started in the design and development of a memory
  10. exploration tool.  QLIB 3+ is required.  With expansion,
  11. this program should provide a much more powerful tool
  12. than its distant ancestor, MEMWALK.COM.
  13.  
  14. QLIB registrants are urged to modify, extend, and
  15. enhance this program and issue it (in compiled form
  16. only) to clients, public domain, etc.  The source code,
  17. however is protected by United States Copyright law.
  18. */
  19.  
  20. #define return_pressed       13          /* Variables returned by    */
  21. #define up_arrow_pressed     0x0148      /* qreadkbd().  See qfocus  */
  22. #define down_arrow_pressed   0x0150      /* screens.                 */
  23. #define bright_white         15          /* color attribute          */
  24. #define hexidecimal          16          /* itoa radix               */
  25. #define period               46          /* ascii "."                */
  26.                                          /*                          */
  27. typedef unsigned char qstring[79];       /*                          */
  28.                                          /*                          */
  29. typedef struct        qmenustructure     /*  Bounce bar menu struct  */
  30.           {                              /*                          */
  31.           int screen_x;                  /*  Upper left column       */
  32.           int screen_y;                  /*  Upper row               */
  33.           int menu_width;                /*  Menu width in columns   */
  34.           int foreground;                /*  Foreground color        */
  35.           int background;                /*  Background color        */
  36.           int option_count;              /*  Total number of options */
  37.           int prior_choice;              /*  Choice last call        */
  38.           qstring title;                 /*  Menu title              */
  39.           qstring option_text[10];       /*  Option list to max of   */
  40.           } qmenurecord;                 /*  ten.                    */
  41.                                          /*                          */
  42.                                          /*                          */
  43.                                          /*                          */
  44. qmenurecord mainmenu =                   /* Declare and initialize in*/
  45.      {                                   /* one step.                */
  46.      24,                                 /* column 24                */
  47.      7,                                  /* row 7                    */
  48.      30,                                 /* 20 columns wide          */
  49.      11,                                 /* bright blue foreground   */
  50.      0,                                  /* black background         */
  51.      4,                                  /* four options (from zero) */
  52.      0,                                  /* Never called before      */
  53.      "[ MAIN MENU ]",                    /* Title                    */
  54.      "BIOS COMMUNICATION AREA",          /* Option 0                 */
  55.      "DOS COMMUNICATION AREA",           /* Option 1                 */
  56.      "HOST SIGNATURE",                   /* Option 2                 */
  57.      "INTERRUPT VECTORS",                /* Option 3                 */
  58.      "QUIT/RETURN TO DOS"                /* Option 4                 */
  59.      };                                  /*                          */
  60.  
  61. void qpad(qstring st, int n)             /* No frills padding, see   */
  62. {                                        /* QLIB 4 for fast function.*/
  63. qstring temp = "";                       /*                          */
  64. qstring blank = " ";                     /*                          */
  65.      while(strlen(st) + strlen(temp)  < n)
  66.           {
  67.           strcat(st, blank);
  68.           strcat(temp, blank);
  69.           }
  70.      strcat(temp, st);
  71.      strcpy(st, temp);
  72.      if (strlen(st) % 2 == n % 2) strcat(st, blank);
  73. }
  74. int qbounce_bar(qmenurecord *m)     /* Returns an integer       */
  75. {                                   /*                          */
  76. unsigned char normal;               /* Normal/reverse get calcu-*/
  77. unsigned char reverse;              /* lated for convenience.   */
  78. int  current_option = 0;            /*                          */
  79. unsigned int  keyvar;               /* See QLIB documentation   */
  80.                                     /*                          */
  81.                                     /*                          */
  82.      qgotoxy(0, 25);                /*                          */
  83.      normal  = ((m ->background<<4) +
  84.                     m ->foreground) & 127;
  85.      reverse = ((m ->foreground<<4) +
  86.                     m ->background) & 127;
  87.      qdrawbox     (                                /* Draw a box to hold the   */
  88.                m ->screen_x - 1,                   /* menu.                    */
  89.                m ->screen_y - 2,                   /*                          */
  90.                m ->screen_x + m ->menu_width + 1,  /*                          */
  91.                m ->screen_y + m ->option_count + 2,/*                          */
  92.                m ->title, "",                      /*                          */
  93.                reverse,                            /*                          */
  94.                normal,                             /*                          */
  95.                normal);                            /*                          */
  96.      for (current_option=0;                        /* Pad the options to center*/
  97.           current_option<=m ->option_count;        /* within the menu width    */
  98.           ++current_option)                        /*                          */
  99.           {                                        /*                          */
  100.           qpad(m ->option_text[current_option],    /*                          */
  101.                m ->menu_width);                    /*                          */
  102.           qsnap                                    /* Display the options      */
  103.                (                                   /*                          */
  104.                m ->option_text[current_option],    /*                          */
  105.                m ->screen_x,                       /*                          */
  106.                m ->screen_y + current_option,      /*                          */
  107.                normal                              /*                          */
  108.                );                                  /*                          */
  109.           }                                        /*                          */
  110.      keyvar = 0;                                   /*                          */
  111.      current_option = m ->prior_choice;            /* Set an initial value for */
  112.      while(keyvar != return_pressed)               /* choice.                  */
  113.           {                                        /*                          */
  114.           qsnap                                    /* Highlight the new option */
  115.                (                                   /*                          */
  116.                m ->option_text[current_option],    /*                          */
  117.                m ->screen_x,                       /*                          */
  118.                m ->screen_y + current_option,      /*                          */
  119.                reverse                             /*                          */
  120.                );                                  /*                          */
  121.           qturn_num_lock_off();                    /*                          */
  122.           keyvar = qreadkbd();                     /* Get the arrow key        */
  123.           qsnap                                    /* Unhighlight the old      */
  124.                (                                   /* option                   */
  125.                m ->option_text[current_option],    /*                          */
  126.                m ->screen_x,                       /*                          */
  127.                m ->screen_y + current_option,      /* Inc/dec according to the */
  128.                normal                              /* keystroke, and wrap      */
  129.                );                                  /* around if upper/lower    */
  130.                                                    /* limits are reached.      */
  131.                                                    /*                          */
  132.                                                    /*                          */
  133.                                                    /*                          */
  134.           if (keyvar == up_arrow_pressed  )      --current_option;
  135.           if (keyvar == down_arrow_pressed)      ++current_option;
  136.           if (current_option > m ->option_count) current_option = 0;
  137.           if (current_option < 0          )       current_option = m ->option_count;
  138.           }                                        /* When a choice is made,   */
  139.      m -> prior_choice = current_option;           /* store it for next time   */
  140.      return(current_option);                       /* and return it as the     */
  141. }                                                  /* function value.          */
  142.  
  143. void qfront_zero                    /* For consistency and pres-*/
  144.   (                                 /* entation, a function is  */
  145.   qstring s,                        /* needed to normalize the  */
  146.   unsigned int  n                   /* length of strings that   */
  147.   )                                 /* contain hexidecimal      */
  148. {                                   /* numbers.  This function  */
  149. qstring temp;                       /* assures that string "s"  */
  150.   strrev(s);                        /* contains at least "n"    */
  151.   while (strlen(s)< n)              /* characters, adding zeros */
  152.      strcat(s, "0");                /* to the beginning of the  */
  153.   strrev(s);                        /* string where needed.     */
  154. }                                   /*                          */
  155. void qpresent_paragraph             /* This function builds and */
  156.   (                                 /* displays a string con-   */
  157.   unsigned int segloc,              /* taining information about*/
  158.   unsigned int offloc,              /* a single paragraph of    */
  159.   unsigned int x,                   /* memory.  The string con- */
  160.   unsigned int y                    /* sists of four main parts:*/
  161.   )                                 /* 1.  the segment address  */
  162. {                                   /* 2.  the offset address   */
  163. qstring ascii_part;                 /* 3.  the hex representa-  */
  164. qstring target_string;              /*     of the paragraph     */
  165. qstring temp;                       /* 4.  the ascii representa-*/
  166. int intvar;                         /*     tion of the paragraph*/
  167.                                     /*                          */
  168.   strcpy                            /* First, set string length */
  169.     (                               /* to zero.                 */
  170.     target_string,                  /*                          */
  171.     ""                              /*                          */
  172.     );                              /* Load the segment address */
  173.   itoa                              /* into the string.         */
  174.     (                               /*                          */
  175.     segloc,                         /*                          */
  176.     target_string,                  /*                          */
  177.     hexidecimal                     /*                          */
  178.     );                              /*                          */
  179.   qfront_zero                       /*                          */
  180.     (                               /*                          */
  181.     target_string,                  /*                          */
  182.     4                               /*                          */
  183.     );                              /*                          */
  184.   strcat                            /* Add a colon to separate  */
  185.     (                               /* the segment from the     */
  186.     target_string,                  /* offset.                  */
  187.     ":"                             /*                          */
  188.     );                              /*                          */
  189.   itoa                              /* Add the offset address   */
  190.     (                               /* to the string.           */
  191.     offloc,                         /*                          */
  192.     temp,                           /*                          */
  193.     hexidecimal                     /*                          */
  194.     );                              /*                          */
  195.   qfront_zero                       /*                          */
  196.     (                               /*                          */
  197.     temp,                           /*                          */
  198.     4                               /*                          */
  199.     );                              /*                          */
  200.   strcat                            /*                          */
  201.     (                               /*                          */
  202.     target_string,                  /*                          */
  203.     temp                            /*                          */
  204.     );                              /*                          */
  205.   strcat                            /* Add two blanks to separ- */
  206.     (                               /* ate the address from the */
  207.     target_string,                  /* hex values.              */
  208.     "  "                            /*                          */
  209.     );                              /*                          */
  210.   for (  intvar=0;                  /* Starting at the segment: */
  211.     intvar<hexidecimal;             /* offset specified, collect*/
  212.     ++intvar)                       /* sixteen bytes.           */
  213.     {                               /*                          */
  214.     ascii_part[intvar] =            /* Keep the ascii values in */
  215.       peekb                         /* a string.                */
  216.         (                           /*                          */
  217.         segloc,                     /*                          */
  218.         offloc + intvar             /*                          */
  219.         );                          /*                          */
  220.     itoa                            /* Convert the ascii values */
  221.       (                             /* to hex values.           */
  222.       ascii_part[intvar],           /*                          */
  223.       temp,                         /*                          */
  224.       hexidecimal                   /*                          */
  225.       );                            /*                          */
  226.     qfront_zero                     /*                          */
  227.       (                             /*                          */
  228.       temp,                         /*                          */
  229.       2                             /*                          */
  230.       );                            /*                          */
  231.     strcat                          /*                          */
  232.       (                             /*                          */
  233.       target_string,                /*                          */
  234.       temp                          /*                          */
  235.       );                            /*                          */
  236.     strcat                          /* Separate hex values with */
  237.       (                             /* a space.                 */
  238.       target_string,                /*                          */
  239.       " "                           /*                          */
  240.       );                            /*                          */
  241.     if (ascii_part[intvar] < 32)
  242.         ascii_part[intvar] = period;
  243.     }                               /*                          */
  244.     ascii_part[hexidecimal] = 0;    /* Terminate the string with*/
  245.     strcat                          /* a zero byte.             */
  246.       (                             /*                          */
  247.       target_string,                /*                          */
  248.       "  "                          /*                          */
  249.       );                            /*                          */
  250.     strcat                          /* Add the ascii string to  */
  251.       (                             /* the hex string.          */
  252.       target_string,                /*                          */
  253.       ascii_part                    /*                          */
  254.       );                            /*                          */
  255.   qsnap                             /* Send the string out      */
  256.     (                               /*                          */
  257.     target_string,                  /*                          */
  258.     x,                              /*                          */
  259.     y,                              /*                          */
  260.     bright_white                    /*                          */
  261.     );                              /*                          */
  262. }                                   /*                          */
  263. void qpresent_page                  /* This function simply     */
  264.   (                                 /* draws a box and calls    */
  265.   unsigned int segment,             /* the present_paragraph    */
  266.   unsigned int offset,              /* function sixteen times.  */
  267.   qstring title                     /*                          */
  268.   )                                 /*                          */
  269. {                                   /*                          */
  270. unsigned int p;                     /*                          */
  271.   qdrawbox                          /* Draw a box               */
  272.     (                               /*                          */
  273.     0,                              /* from column 0            */
  274.     0,                              /* and row 0                */
  275.     79,                             /* to column 79             */
  276.     17,                             /* row 17                   */
  277.     title,                          /* with a top title "title" */
  278.     "",                             /* no bottom title          */
  279.     5,                              /* magenta box border       */
  280.     115,                            /* blue on white title      */
  281.     0                               /* no bottom title          */
  282.     );                              /*                          */
  283.   for (  p=0;                       /* Draw sixteen paragraphs  */
  284.     p<hexidecimal;                  /*                          */
  285.     ++p)                            /*                          */
  286.     {                               /*                          */
  287.     qpresent_paragraph              /*                          */
  288.       (                             /*                          */
  289.       segment,                      /*                          */
  290.       offset,                       /*                          */
  291.       1,                            /*                          */
  292.       p + 1                         /*                          */
  293.       );                            /*                          */
  294.     offset += 0x0010;               /*                          */
  295.     }                               /*                          */
  296.   qgotoxy(0, 25);                   /* Hide the cursor          */
  297.   qcenter_line                      /* Send out a prompt        */
  298.     (                               /*                          */
  299.     " Hit almost any key to continue ",
  300.     24,                             /*                          */
  301.     116                             /*                          */
  302.     );                              /*                          */
  303.   p = qreadkbd();                   /* Wait for a keystroke     */
  304. }                                   /*                          */
  305.  
  306. /****************************************************************/
  307. /*                mainline starts here                          */
  308. /****************************************************************/
  309. main()
  310. {
  311. unsigned int user_choice = 0;
  312.  
  313.      while (user_choice != mainmenu.option_count)
  314.           {
  315.           qclrscr(bright_white);
  316.           qcenter_line(" Q-MEM:  a qlib product ", 0, 113);
  317.           user_choice = qbounce_bar(&mainmenu);
  318.           qclrscr(bright_white);
  319.           if (user_choice == 0)
  320.             {
  321.             qpresent_page(0x0000, 0x0400, "[ BIOS COMMUNICATION AREA ]");
  322.             }
  323.           if (user_choice == 1)
  324.             {
  325.             qpresent_page(0x0000, 0x0500, "[ DOS COMMNUNICATION AREA ]");
  326.                 }
  327.           if (user_choice == 2)
  328.             {
  329.             qpresent_page(0xf000, 0xfff5, "[ HOST SIGNATURE ]");
  330.             }
  331.           if (user_choice == 3)
  332.             {
  333.             qpresent_page(0x0000, 0x0000, "[ INTERRUPT VECTORS ]");
  334.             }
  335.           }
  336.   qclrscr(bright_white);
  337.   qgotoxy(0, 24);
  338. }
  339.         /* a zero byte.             */
  340.       (                             /*